/*
负责与后台交互 发送请求
 */
import ajax from '@/api/ajax'
const MY_URL='http://127.0.0.1:8000'
/**
 * const BASE_URL='/api'
 * 两种方式
 * 1.'${BASE_URL}/position/...'
 * 2.BASE_URL+'/index/...'
 */

//账号密码登录
export const reqPwdLogin = (name, pwd) => ajax('/user/login', {
    name,pwd
  }, 'POST')

//用户的注册
 export const reqPwdRegister = (name,acc,pwd)=>ajax('/user/register',{
    name,acc,pwd
 },' POST') 

/*
创建在线文档  返回 error_code 以及articleid
 */
export const reqCreate = (userid,content,title) => ajax('document/flNew',{
  userid,content,title
},'POST')


//获取现在的文档内容

export const reqFetch = (did,userid) => ajax('document/docRead',{
  did,userid
},'GET')


//修改文档

export const reqUpdate = (name,did,content,userid) => ajax('document/docWrite',{
  name,did,content,userid
},'POST')

/*
发表评论
 */
export const reqAddComment = (userid,did,auth,content) => ajax('document/docCommentCreate',{
  userid,did,auth,content
},'POST')



//获取所有评论  返回字段以及comment列表
export const reqGetComment = (userid,did) => ajax('document/docCommentGetAll',{
  userid,did
},'POST')


/*
文档收藏与否
islike  0取消收藏 1收藏
 */
export const reqLikeornotArticle = (articleid,is_starred,userid) => ajax('document/flStar',{
  articleid,is_starred,userid
},'POST')

//返回状态码 个人信息
export const reqGetStatus = () => ajax('user/getInfo' )



/*
获取所有创建
 */
export const reqGetAllCreateArticle = (userid) => ajax('document/workbenchCreate',{userid},'GET')

/*
获取所有创建（异步）
 */
export const reqGetAllCreateArticleYi = (userid) =>ajax('document/workbenchCreate',{userid},'GET')

/*
获取所有收藏
 */
export const reqGetAllLikesArticle = (userid) => ajax('document/workbenchStar',{userid},'GET')

/*
获取所有收藏（异步）
 */
export const reqGetAllLikesArticleYi = (userid) => ajax('document/workbenchStar',{userid},'GET')

/*
  删除文档
 */
export const reqDeleteArticle = (articleid,userid) => ajax('document/flDelete',{articleid,userid},'POST')


//创建团队文档
export const reqCreateTeamArticle = (userid,tid,title,content)=>ajax('teamwork/teamDocNew',{userid,tid,title,content},'POST')

/*
彻底删除回收站内的文档 

 */
export const reqCompleteDeleteArticle = (articleid,userid) => ajax('document/recycleBinDeleteElem',{articleid,userid},'POST')




/*
用户退出
 */

export const reqPwdLogout = () => ajax('user/logout')

/*
修改个人信息
*/

export const reqChange = (name,intro,img) => ajax('user/putInfo',{name,intro,img},'POST')

export const reqChange2 = (uname,intro,img,userid) => ajax('user/putInfo2',{uname,intro,img,userid},'POST')

/*
查看个人信息
 */

export const reqGet = (formData) => ajax('/apis/personality/get',formData,'POST')


/*
获得验证码
*/

export const reqGetCode =(acc)=>ajax('/user/forget/sendCode',{acc},'POST')


/*
  通过验证码重置密码
*/

export const reqReset =(acc,pwd,key)=>ajax('user/forget/setPwd',{acc,pwd,key},'POST')
/*
查看文档
 */

/*
修改文档
 */




/*
获取评论
 */

/*
释放互斥锁
 */
export const reqReleaseLock = (articleid) => ajax('apis/article/releaselock',{
  articleid
},'POST')

/*
恢复文档
 */
export const reqRecoverArticle = (articleid,userid) => ajax('document/recycleBinRecover',{articleid,userid},'POST')

/*
清空回收站 
*/
export const reqClearAll = (userid) => ajax('document/recycleBinClear',{userid},'GET')

/*
获取最近浏览的文档
 */
export const reqGetRecentArticle = (userid) => ajax('/apis/article/getrecentwatch',{userid},'POST')

/*
获取最近浏览的文档（异步）
 */
export const reqGetRecentArticleYi = (userid) =>ajax('document/workbenchRencent',{userid},'GET')





/*
获取回收站文档
 */
export const reqGetGarbageArticle = (userid) => ajax('document/recycleBinElem',{userid},'GET')

/*
异步获取回收站文档
 */
export const reqGetGarbageArticleYi = (userid) => ajax('document/recycleBinElem',{userid},'GET')

/*
改变文档修改状态
 */
export const reqUpdatingcodeArticle = (updatingcode,articleid) => ajax('/apis/article/updatingcodechange',{
  updatingcode,articleid
},'POST')

/*
获取登录验证码
 */
export const reqGetValidCode = () => ajax('/apis/user/getvalidcode','','POST')

/*
创建团队
 */
export const reqCreateTeam = (name,userid) => ajax('teamwork/newTeam', {name,userid},'POST')

/*
加入团队
 */
export const reqJoinTeam = (teamid,userid) => ajax('/apis/workplace/jointeam',{teamid,userid},'POST')

/*
退出团队
 */
export const reqExitTeam = (tid,userid) => ajax('teamwork/memberQuit',{tid,userid},'POST')

/*
解散团队
 */
export const reqDisband = (tid,userid) => ajax('teamwork/deleteTeam',{tid,userid},'POST')

/*
获取全部加入的团队
 */
export const reqMyJoinTeam = (userid) => ajax('/apis/workplace/myjointeam',{userid},'POST')

/*
获取全部加入的团队（异步）
 */
export const reqMyJoinTeamYi = () => ajax('/apis/workplace/myjointeamYi',{},'POST')

/*
获取某个团队的所有成员
 */
export const reqGetTeamMember = (tid,userid) => ajax('teamwork/teamInfo',{tid,userid},'GET')

/*
获取某个团队的所有文档
 */
export const reqGetAllArticles = (teamid,userid) => ajax('teamwork/teamAllDoc',{teamid,userid},'GET')

/*
获取创建的所有团队
 */
export const reqMyCreateTeam = (userid) => ajax('teamwork/getAllTeam',{userid},'GET')

/*
获取创建的所有团队（异步）
 */
export const reqMyCreateTeamYi = (userid) => ajax('teamwork/getAllTeam',{userid},'GET')

/*
获取团队信息
 */
export const reqTeamInfo = (teamid) => ajax('/apis/workplace/getteaminfo',{teamid},'POST')

//获取团队成员权限
export const reqGetAuth =(userid,tid)=>ajax('teamwork/getTeamAuth',{userid,tid},'GET')

/*
修改权限
*/

export const reqChangeAuth=(tid,userid,auth,is_new,acc)=>ajax('/teamwork/invitatate',{tid,userid,auth,is_new,acc},'POST')
/*
全局搜索用户
 */
export const reqSearchUser = (keyword) => ajax('/apis/search/users',{keyword},'POST')

/*
全局搜索文档
 */
export const reqSearchDoc = (userid,key) => ajax('document/searchDocument',{userid,key},'POST')

/*
全局搜索团队
 */
export const reqSearchTeam = (userid,keyword) => ajax('/apis/workplace/searchteam',{userid,keyword},'POST')

/*
踢人
 */
export const reqOutTeam = (tid,userid,uid) => ajax('teamwork/removeMember',{tid,userid,uid},'POST')

// ================================消息通知===========================

/*
邀请用户
 */
export const reqSearchInviteUser = (tid,userid,auth,is_new,acc) => ajax('teamwork/invitatate',{tid,userid,auth,is_new,acc},'POST')

/*
邀请用户加入团队消息
 */
export const reqInviteUser = (teamid,inviteduserid,userid) => ajax('/apis/message/invite',{teamid,inviteduserid,userid},'POST')

/*
评论生成消息通知
 */
export const reqCommentMessage = (articleid,userid) => ajax('/apis/message/commentmessage',{articleid,userid},'POST')

/*
接收团队消息通知列表
 */
export const reqGetTeamMessage = (userid) => ajax('user/askForMessageListUnread',{userid},'GET')

/*
接收评论消息通知
 */
export const reqGetCommentMessage = (userid) => ajax('/apis/message/getcommentmessage',{userid},'POST')

/*
删除评论消息通知
 */
export const reqSolveCommentMessage = (messageid) => ajax('/apis/message/solvecommentmessage',{messageid},'POST')

/*
设置已读，从而删除团队消息通知
 */
export const reqSolveTeamMessage = (mid) => ajax('user/setMessageRead',{mid},'POST')

/*
退出团队消息通知(给团队创建者发送消息通知)
 */
export const reqExitTeamMessage = (userid,teamid) => ajax('/apis/message/exitteammessage',{userid,teamid},'POST')

/*
踢人消息通知(给被踢用户发送消息通知)
 */
export const reqOutTeamMessage = (teamid,outuserid,userid) => ajax('/apis/message/outteammessage',{
  teamid,outuserid,userid
},'POST')

/*
同意邀请消息通知(发给团队创建者)
 */
export const reqAgreeInvitation = (mid,userid,result) => ajax('teamwork/invitationDeal',{
  mid,userid,result
},'POST')

/*
拒绝邀请消息通知(发给团队创建者)
 */
export const reqRefuseInvitation = (teamid,inviteuserid,userid) => ajax('/apis/message/refuseinvitation',{
  teamid,inviteuserid,userid
},'POST')

/*
申请加入团队(发给团队创建者)
 */
export const reqApply = (teamid,userid) => ajax('/apis/message/apply',{teamid,userid},'POST')

/*
同意申请消息通知(发给申请用户)
 */
export const reqAgreeApply = (teamid,applyuserid,userid) => ajax('/apis/message/agreeapply',{
  teamid,applyuserid,userid
},'POST')

/*
拒绝申请消息通知(发给申请用户)
 */
export const reqRefuseApply = (teamid,applyuserid,userid) => ajax('/apis/message/refuseapply',{
  teamid,applyuserid,userid
},'POST')

/*
发送私信
 */
export const reqSendPrivateMessage = (userid,message,touserid) => ajax('/apis/chat/sendmessage',{
  userid,message,touserid
},'POST')

/*
接收私信
 */
export const reqGetPrivateMessage = (userid) => ajax('/apis/chat/getmessage',{userid},'POST')

/*
删除私信
 */
export const reqDeletePrivateMessage = (messageid) => ajax('/apis/chat/deletemessage',{messageid},'POST')
